package com.ch.tools.client.simulator.observer;

import com.ch.tools.client.simulator.controller.ServerListViewController;
import com.ch.tools.client.simulator.observable.MapleServerPacketObservable;
import javafx.application.Platform;
import javafx.collections.FXCollections;

import java.util.Observable;
import java.util.Observer;

public class MapleWorldServersObserver implements Observer {

    private ServerListViewController serverListViewController;


    public MapleWorldServersObserver(ServerListViewController serverListViewController) {
        this.serverListViewController = serverListViewController;
    }

    @Override
    public void update(Observable o, Object arg) {

        MapleServerPacketObservable mapleWorldServerPacketObservable = (MapleServerPacketObservable) o;

        Platform.runLater(() -> {

            serverListViewController.getServerListView().setItems(FXCollections.observableArrayList(mapleWorldServerPacketObservable.getMapleServers()));


        });
    }
}
